home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Workbench / Archive / XPK / xpk_Source / examples / XpkManx.c < prev    next >
C/C++ Source or Header  |  1998-11-15  |  2KB  |  84 lines

  1. /* XPK - General XPK file-to-file packer/unpacker */
  2. /* This is the version to be compiled with Manx C */
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <dos/dos.h>
  8. #include <xpk/xpk.h>
  9. #include <proto/xpkmaster.h>
  10.  
  11. long chunkfunc (struct XpkProgress *prog);
  12. #pragma regcall(chunkfunc(a1))
  13.  
  14. struct Library *XpkBase, *OpenLibrary (UBYTE * libName, ULONG version);
  15.  
  16. char errbuf[XPKERRMSGSIZE + 1];    /* +1 to make room for '\n'        */
  17.  
  18. long chunkfunc (struct XpkProgress *prog)
  19. {
  20.   long abort = (long) SetSignal (0, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C;
  21.  
  22.   printf ("\r%4s: %-9s %-12s (%6d bytes, %3d%% done, %2d%% CF, %6d cps) ",
  23.     prog->xp_PackerName, prog->xp_Activity, prog->xp_FileName,
  24.     prog->xp_ULen, prog->xp_Done, prog->xp_CF, prog->xp_Speed);
  25.   fflush (stdout);
  26.   if(prog->xp_Type == XPKPROG_END || abort)
  27.     printf ("\n");
  28.  
  29.   return abort;
  30. }
  31. struct Hook chunkhook =
  32. { {0}, (void *) chunkfunc};
  33.  
  34. struct TagItem tags[]=
  35. {
  36.   XPK_InName, (long) NULL,
  37.   XPK_OutName, (long) NULL,
  38.   XPK_GetError, (long) NULL,
  39.   XPK_ChunkHook, (long) NULL,
  40.   XPK_Ignore, (long) 0,
  41.   XPK_NoClobber, (long) TRUE,
  42.   TAG_DONE};
  43.  
  44. void  end (char *text)
  45. {
  46.   if (text)
  47.     Write (Output (), text, strlen (text));
  48.   if (XpkBase)
  49.     CloseLibrary (XpkBase);
  50.   exit (text ? 10 : 0);
  51. }
  52.  
  53. extern int Enable_Abort;
  54.  
  55. void main (int argc, char *argv[])
  56. {
  57.   int res;
  58.  
  59.   Enable_Abort = 0;
  60.  
  61.   if (!(XpkBase = OpenLibrary ((STRPTR) XPKNAME, 0)))
  62.     end ("Cannot open " XPKNAME "\n");
  63.  
  64.   if ((argc < 3) || (argc > 4))
  65.     end ("Usage: XPK [<method>] <infile> <outfile>\n");
  66.  
  67.   tags[0].ti_Data = (long) argv[argc - 2];    /* First try to decompress... */
  68.   tags[1].ti_Data = (long) argv[argc - 1];
  69.   tags[2].ti_Data = (long) errbuf;
  70.   tags[3].ti_Data = (long) &chunkhook;
  71.  
  72.   if (argc == 3)
  73.     res = XpkUnpack (tags);
  74.   else {
  75.     tags[4].ti_Tag = XPK_PackMethod;
  76.     tags[4].ti_Data = (long) argv[1];
  77.     res = XpkPack (tags);
  78.   }
  79.   if (res)
  80.     end (strcat (errbuf, "\n"));
  81.  
  82.   end (NULL);
  83. }
  84.